<?php
    if (COUNT($_POST))
    {
        $u = $this->get('username');
        $p = $this->get('password');
        $f = $this->get('firstname');
        $l = $this->get('lastname');
        $i = $this->get('institution');
        $e = $this->get('email');
        $a = $this->get('address');
        $c = $this->get('contact');
		if (strlen($u) > 0 && strlen($p) > 0){
            Connection::getConnect();
            $sql = "SELECT aid FROM login WHERE userid='%s'";
            Connection::setQueryf($sql, $u);
            $fetch = Connection::fetch();
            $sql = "SELECT aid FROM login WHERE email='%s'";
            Connection::setQueryf($sql, $e);
            $fetch1 = Connection::fetch();
            if (!$fetch[0] && !$fetch1[0])
            {
                $sql = "INSERT INTO login(userid, password, first_name, last_name, email, institution, address, contact) VALUES('%s', MD5('%s'), '%s', '%s', '%s', '%s', '%s', '%s')";
                Connection::setQueryf($sql, $u, $p, $f, $l, $e, $i, $a, $c);
    			$this->message = "You may now <a href='http://localhost/lvt-web-pos/trunk/?module=login'>login</a>.";
            } //$fetch[0] > 0
            else
            {
				if($fetch[0])
                	$this->error = "Username already taken.";
				if($fetch1[0])
                	$this->error = "Email already taken.";
            }
		}
    } //COUNT($_POST)
?>